package com.group6.exam.teacher.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.group6.exam.teacher.dao.IScoreDao;
import com.group6.exam.teacher.dao.ScoreDaoImpl;
import com.group6.exam.teacher.entity.ScoreCondition;
import com.group6.exam.teacher.entity.ScorePage;

public class ScoreServiceImpl implements IScoreService {

	private IScoreDao scoreDao = new ScoreDaoImpl();

	/**
	 * 分页查询
	 */
	@Override
	public ScorePage getScoreInfoByScorePage(ScorePage scorePage,
			ScoreCondition condition) {

		// 构建创建page对象所需参数
		int totalRecords = scoreDao.getTotalRecords(condition);
		int pageSize = scorePage.getPageSize();

		ScorePage page = new ScorePage(totalRecords, pageSize);
		// 设置当前页
		page.setCurrentPage(scorePage.getCurrentPage());

		// 设置每页显示数据的集合对象
		List<Map<String, Object>> list = scoreDao.getPagingByScorePage(
				scorePage, condition);
		List<Map<String, Object>> mapList = new ArrayList<>();

		for (Map<String, Object> map : list) {
			// 获取商品类型编号
			String classId = map.get("score_grade_id") + "";
			String studentId = map.get("score_student_id") + "";
			String subjectId = map.get("score_subject_id") + "";
			// 通过typeId获取typeName
			String className = scoreDao.getClassNameById(classId);
			String studentName = scoreDao.getStudentNameById(studentId);
			String subjectName = scoreDao.getSubjectNameById(subjectId);

			map.put("className", className);
			map.put("studentName", studentName);
			map.put("subjectName", subjectName);

			mapList.add(map);
		}
		page.setList(mapList);

		return page;
	}

	// 通过科目名称获取科目id
	@Override
	public String getScoreBySubName(String subStr) {

		return scoreDao.getScoreBySubName(subStr);
	}

	// 通过班级名查询班级id
	@Override
	public String getScoreByClaName(String claStr) {

		return scoreDao.getScoreByClaName(claStr);
	}

	// 通过班级名查询班级id
	@Override
	public String getScoreByStuName(String stuStr) {

		return scoreDao.getScoreByStuName(stuStr);
	}

}
